::*********************************************************************************************************************
:: 文 件 名: 输出工程.bat
:: 功    能: 输出工程到SDK中
::
:: 作    者: zhangys
:: 创建时间: 2021.08.24
::
:: 日    志：
:: [2021.08.24] 建立。
::*********************************************************************************************************************
@echo off

::0. 定义Example名称
for /f "delims=" %%i in ("%cd%") do set ExampleName=%%~ni

::1.如果有..\NL8507_ExampleName, 则删除NL8507_ExampleName
if exist ..\NL8507_%ExampleName% rd /s /q ..\NL8507_%ExampleName%

::2.如果没有..\NL8507_ExampleName文件夹，则新建..\NL8507_ExampleName文件夹
if not exist ..\NL8507_%ExampleName% md ..\NL8507_%ExampleName%

::3.创建Tools文件夹，并且添加相关文件
md ..\NL8507_%ExampleName%\Tools
copy ..\..\Tools\PostBuildCmd.bat   ..\NL8507_%ExampleName%\Tools\

::4.创建Includes文件夹，并且添加相关文件
md ..\NL8507_%ExampleName%\Includes
copy ..\..\Includes\GlobalConfig.h   ..\NL8507_%ExampleName%\Includes\

::5.创建Utilities文件夹，并且添加相关文件
md ..\NL8507_%ExampleName%\Utilities
@REM xcopy /s/y/i/f ..\..\Utilities\SimpleUart       ..\NL8507_%ExampleName%\Utilities\SimpleUart

::6.创建Drivers文件夹，并且添加相关文件
md ..\NL8507_%ExampleName%\Drivers
md ..\NL8507_%ExampleName%\Drivers\51SIS
copy ..\..\Drivers\51SIS\NL8507.h        ..\NL8507_%ExampleName%\Drivers\51SIS\NL8507.h

md ..\NL8507_%ExampleName%\Drivers\NL8507_StdPeriph_Driver
xcopy /s/y/i/f ..\..\Drivers\NL8507_StdPeriph_Driver\Inc ..\NL8507_%ExampleName%\Drivers\NL8507_StdPeriph_Driver\Inc
xcopy /s/y/i/f ..\..\Drivers\NL8507_StdPeriph_Driver\Src ..\NL8507_%ExampleName%\Drivers\NL8507_StdPeriph_Driver\Src

::7.创建Examples文件夹，并且添加相关文件
xcopy /s/y/i/f ..\..\Examples\%ExampleName%                       ..\NL8507_%ExampleName%\Examples\%ExampleName%

::8.清除相关文件
del /s /q ..\NL8507_%ExampleName%\NL8507_%ExampleName%_%Date_Time%.rar
del /s /q ..\NL8507_%ExampleName%\Examples\%ExampleName%\*.hex
del /s /q ..\NL8507_%ExampleName%\Examples\%ExampleName%\*.rar
del /s /q ..\NL8507_%ExampleName%\Examples\%ExampleName%\*.lst
del /s /q ..\NL8507_%ExampleName%\Examples\%ExampleName%\MPLAB_8.92\*.dep
del /s /q ..\NL8507_%ExampleName%\Examples\%ExampleName%\MPLAB_8.92\*.mcs
del /s /q ..\NL8507_%ExampleName%\Examples\%ExampleName%\MPLAB_8.92\*.mptags
del /s /q ..\NL8507_%ExampleName%\Examples\%ExampleName%\MPLAB_8.92\*.tagsrc
del /s /q ..\NL8507_%ExampleName%\Examples\%ExampleName%\MPLAB_8.92\Output\*.*

::9.压缩文件
cd ..
set "Date_Time=%date:~0,4%%date:~5,2%%date:~8,2%_%TIME:~0,2%%TIME:~3,2%"
set "Date_Time=%Date_Time: =0%"
"D:\WinRAR\WinRAR.exe" a  NL8507_%ExampleName%_%Date_Time%.rar  NL8507_%ExampleName%
cd .\%ExampleName%

::10.如果压缩文件没有打成功，则输出文件夹
if not exist ..\NL8507_%ExampleName%_%Date_Time%.rar xcopy /s/y/i/f ..\..\Examples\NL8507_%ExampleName%             ..\..\Examples\%ExampleName%\NL8507_%ExampleName%

::11.如果压缩文件成功，则输出压缩文件
copy ..\..\Examples\NL8507_%ExampleName%_%Date_Time%.rar   ..\..\Examples\%ExampleName%\

::12.删除临时文件
rd /s /q  ..\NL8507_%ExampleName%
del    ..\NL8507_%ExampleName%_%Date_Time%.rar


::延迟关闭
::ping -n 1 127.0.0.1 >nul





